package com.brainhealth.utils;

import com.brainhealth.common.enums.CustomerChatStatus;
import com.brainhealth.common.enums.CustomerExerciseStatus;
import com.brainhealth.common.enums.UserStatus;
import com.brainhealth.common.utils.DateCalcUtils;
import com.brainhealth.common.utils.DateUtils;
import com.brainhealth.customer.domain.*;
import com.brainhealth.customer.mapper.ExerciseProductMapper;
import org.springframework.beans.BeanUtils;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

public class FillBeanUtils
{
    /**
     * 填充会员产品的训练记录对象集合
     * @param exerciseProduct
     * @param exerciseOrder
     * @return
     */
    public static List<CustomerExercise> fillCustomerExerciseList(ExerciseProduct exerciseProduct, ExerciseOrder exerciseOrder)
    {
        List<CustomerExercise> lstCustomerExercise = new ArrayList<>();
        for (Exercise exercise : exerciseProduct.getExerciseList())
        {
            CustomerExercise customerExercise = new CustomerExercise();
            BeanUtils.copyProperties(exercise, customerExercise);
            customerExercise.setCustomerId(exerciseOrder.getCustomerId());
            customerExercise.setExerciseName(exercise.getName());
            customerExercise.setStatus(CustomerExerciseStatus.NoOpen);
            customerExercise.setOrderId(exerciseOrder.getOrderId());
            customerExercise.setExerciseType(Long.valueOf(exercise.getExerciseType().getCode()));
            customerExercise.setStatusValue(Long.valueOf(CustomerExerciseStatus.NoOpen.getValue()));
            customerExercise.setCreateTime(new Date());
            if (exercise.getCountSort() == 1)
            {
                customerExercise.setOpenTime(DateCalcUtils.addHour(new Date(),-9));
                customerExercise.setStatus(CustomerExerciseStatus.NoFinish);
                customerExercise.setStatusValue(Long.valueOf(CustomerExerciseStatus.NoFinish.getValue()));
            }
            lstCustomerExercise.add(customerExercise);
        }
        return lstCustomerExercise;
    }

    /**
     * 填充会员基础信息
     * @param phone 手机号
     * @return
     */
    public static Customer fillCustomerInfo(String phone)
    {
        Customer customer = new Customer();
        customer.setCreateTime(DateUtils.getNowDate());
        customer.setPhone(phone);
        customer.setLevelValue(0l);
        customer.setCustomerLevelId(1l);
        customer.setIsBlack(UserStatus.OK.getCode());
        customer.setChatStatus(CustomerChatStatus.Register);
        customer.setLoginTime(new Date());
        customer.setCountSort(1l);
        return customer;
    }
}
